package com.recharge.controller;

import java.math.BigDecimal;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.recharge.base.ResponseInfo;
import com.recharge.base.ResponseInfoEnum;
import com.recharge.wk.domain.Product;
import com.recharge.wk.domain.ProductSup;
import com.recharge.wk.domain.TradeSaleprice;
import com.recharge.wk.mapper.ITradeSalepriceMapper;


@Controller
@RequestMapping("/saleprice")
public class TradeSalepriceController {

    @Autowired
    private ITradeSalepriceMapper iTradeSalepriceMapper;
    
    @RequestMapping("/queryList")
    @ResponseBody
    public ResponseInfo queryList(
            @RequestParam("merchantId") String merchantId,
            @RequestParam("salePrice") Double salePrice,
            @RequestParam("productId") String productId,
            @RequestParam("productName") String productName, 
            @RequestParam("curr") Integer curr,
            @RequestParam("pageSize") Integer pageSize) {
        ResponseInfo responseInfo = new ResponseInfo();
        
        TradeSaleprice tradeSaleprice = new TradeSaleprice();
        tradeSaleprice.setMerchantId(merchantId);
        tradeSaleprice.setSalePrice(salePrice);
        tradeSaleprice.setProductId(productId);
        tradeSaleprice.setProductName(productName);
        
        
        List<TradeSaleprice> saleprice = iTradeSalepriceMapper.selectList(tradeSaleprice, curr, pageSize);
        responseInfo.setCount(iTradeSalepriceMapper.count(tradeSaleprice));
        responseInfo.setData(saleprice);
        return responseInfo;
    }
    
    @RequestMapping("/addInfo")
    @ResponseBody
    public ResponseInfo addInfo(
    		@RequestParam("merchantId") String merchantId,
            @RequestParam("salePrice") Double salePrice,
            @RequestParam("productId") String productId,
            @RequestParam("productName") String productName,
            HttpServletRequest request) {
        ResponseInfo responseInfo = new ResponseInfo();
        TradeSaleprice tradeSaleprice = new TradeSaleprice();
        tradeSaleprice.setMerchantId(merchantId);
        tradeSaleprice.setSalePrice(salePrice);
        tradeSaleprice.setProductId(productId);
        tradeSaleprice.setProductName(productName);
        iTradeSalepriceMapper.insert(tradeSaleprice);
        responseInfo.setInfoEnum(ResponseInfoEnum.SUCCESS);
        return responseInfo;
    }
    
    @RequestMapping("/delete")
    @ResponseBody
    public void deleteInfo(@RequestParam("productId")String productId,@RequestParam("type")String type){
    	if (StringUtils.equals("delete",type)){
    		iTradeSalepriceMapper.delete(productId);
    	}
    }
    
    @RequestMapping("/updateInfo")
    @ResponseBody
    public ResponseInfo updateInfo(
    		@RequestParam("merchantId") String merchantId,
            @RequestParam("salePrice") Double salePrice,
            @RequestParam("productId") String productId,
            @RequestParam("productName") String productName) {
        ResponseInfo responseInfo = new ResponseInfo();

        TradeSaleprice tradeSaleprice = new TradeSaleprice();
        tradeSaleprice.setMerchantId(merchantId);
        tradeSaleprice.setSalePrice(salePrice);
        tradeSaleprice.setProductId(productId);
        tradeSaleprice.setProductName(productName);

        iTradeSalepriceMapper.update(tradeSaleprice);
        responseInfo.setInfoEnum(ResponseInfoEnum.SUCCESS);
        return responseInfo;
    }
}
